package org.darcy.service.check.impl;

import java.util.List;

import org.darcy.dao.CheckPlanDetailMapper;
import org.darcy.entity.CheckPlanDetail;
import org.darcy.framework.generic.GenericServiceImpl;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.service.check.CheckPlanDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * CheckPlanDetail服务实现
 */
@Service
@Transactional
public class CheckPlanDetailServiceImpl extends GenericServiceImpl<CheckPlanDetail> implements CheckPlanDetailService {

	@Autowired
	private CheckPlanDetailMapper mapper;

	@Override
	public CheckPlanDetail getDetail(Integer id) {
		CheckPlanDetail record = mapper.selectById(id);
		return record;
	}

	@Override
	public CheckPlanDetail update(CheckPlanDetail data) {
		int a = 1, b = 1, c = 1;
		if (data.getCheckSpotCount() != null) {
			a = data.getCheckSpotCount();
		}
		if (data.getCheckFreq() != null) {
			b = data.getCheckFreq();
		}
		if (data.getCheckCycle() != null) {
			c = data.getCheckCycle();
		}
		data.setCheckItemCount(a * b * c);
		data.setCheckFee(data.getCheckItemCount() * (data.getCheckPrice() + data.getCollectPrice()));
		super.update(data);
		return data;
	}

	@Override
	public PageData<CheckPlanDetail> page(PageParam<CheckPlanDetail> param) {
		PageData<CheckPlanDetail> data = super.getPageData(param);
		return data;
	}

	@Override
	public List<CheckPlanDetail> getList(Integer planId) {
		QueryWrapper<CheckPlanDetail> q = new QueryWrapper<CheckPlanDetail>();
		q.eq("plan_id", planId);
		return this.getList(q);
	}

}
